using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MedicalManagementSystem.Helpers
{
    public static class JSHelper
    {
        public static string JSNewArray(string arrName, IEnumerable<string> elements, string suffix)
        {
            StringBuilder result = new StringBuilder();
            result.Append("var ").Append(arrName).Append(" = [");

            result.Append(String.Join(",", elements.ToArray()));

            result.Append("]").Append(suffix);

            return result.ToString();
        }

        public static string JSDictionary(string arrayName, IDictionary<int, string> elements)
        {
            StringBuilder result = new StringBuilder();
            result.Append(ArrayDeclaration(arrayName));
            foreach (var element in elements)
            {
                result.Append(string.Format("{0}['{1}']='{2}';", arrayName, element.Key, element.Value));
            }
            return result.ToString();
        }

        private static string ArrayDeclaration(string arrayName)
        {
            return string.Format("var {0} = new Array();",arrayName);
        }
    }
}